import { config } from '../config'
import { isNull } from '../utils/index'

export default {
  
  showLoading(){
    wx.showLoading({
      // title:'加载中',
      mask:true 
    })
  },
  hideLoading(){
    wx.hideLoading({
      // title:'加载中',
      mask:true
    })
  },

	// 信息提示
	msg(msg) {
	  return wx.showToast({
	    title: msg,
	    icon: 'none',
	    duration: 2000
	  })
	},

	success(msg){
		return wx.showToast({
	    title: msg,
			icon: 'success',
			mask: true,
			duration: 2000
	  })
	},

	fail(msg) {
		return wx.showToast({
	    title: msg,
	    icon: 'error',
	    duration: 2000
	  })
	},


  // 确认窗体
	confirm({title,content,confirmText,confirmColor,cancelText,cancelColor,success}) {
    console.log(config())
		if(isNull(title)){
			title = config().style.confirm.title;
		}
		if(isNull(confirmText)){
			confirmText = config().style.confirm.confirmText;
		}
		if(isNull(confirmColor)){
			confirmColor = config().style.confirm.confirmColor
		}
		if(isNull(cancelText)){
			cancelText = config().style.confirm.cancelText;
		}
		if(isNull(cancelColor)){
			cancelColor = config().style.confirm.cancelColor;
    }
    if(isNull(success)){
      success = function(res){
        // if (res.confirm) {
				// 	console.log('用户点击确定');
				// } else if (res.cancel) {
				// 	console.log('用户点击取消');
				// }
      }
    }
		wx.showModal({
			title: title,
			content: content,
			cancelText: cancelText, // 取消按钮的文字  
			confirmText: confirmText, // 确认按钮文字 
			confirmColor: confirmColor,//确认字体的颜色
			cancelColor: cancelColor,//取消字体的颜色
			mask: true,
      success: success,
      fail:function(res){
        console.log(res)
      }
		})
	}
}